###############################################################################
# vector2
#
class vector2:
	"""
	vector2()
	vector2([x,y])
	"""

	def __init__(self, vector = None):
		self.data = [0.0, 0.0]
		if vector != None:
			self.data[0] = vector[0]
			self.data[1] = vector[1]

	def __getitem__(self, index):
		if index == 0:
			returnValue = self.data[0]
		elif index == 1:
			returnValue = self.data[1]
		return returnValue

	def __call__(self, vector = None):
		if vector != None:
			self.data[0] = vector[0]
			self.data[1] = vector[1]
		else:
			return vector2([self.data[0], self.data[1]])

	def __str__(self):
		return str([self.data[0], self.data[1]])

	def __add__(self, other):
		if type(other) == type(self):
			returnValue = vector2([self.data[0] + other.data[0], self.data[1] + other.data[1]])
		elif type(other) == type(0.0) or type(other) == type(0):
			returnValue = vector2([self.data[0] + other, self.data[1] + other])
		else:
			returnValue = None
		return returnValue

	def __iadd__(self, other):
		if type(other) == type(self):
			self.data[0] += other.data[0]
			self.data[1] += other.data[1]
			returnValue = vector2([self.data[0], self.data[1]])
		elif type(other) == type(0.0) or type(other) == type(0):
			self.data[0] += other
			self.data[1] += other
			returnValue = vector2([self.data[0], self.data[1]])
		else:
			pass
		return returnValue

	def __sub__(self, other):
		if type(other) == type(self):
			returnValue = vector2([self.data[0] - other.data[0], self.data[1] - other.data[1]])
		elif type(other) == type(0.0) or type(other) == type(0):
			returnValue = vector2([self.data[0] - other, self.data[1] - other])
		else:
			returnValue = None
		return returnValue

	def __isub__(self, other):
		if type(other) == type(self):
			self.data[0] -= other.data[0]
			self.data[1] -= other.data[1]
			returnValue = vector2([self.data[0], self.data[1]])
		elif type(other) == type(0.0) or type(other) == type(0):
			self.data[0] -= other
			self.data[1] -= other
			returnValue = vector2([self.data[0], self.data[1]])
		else:
			returnValue = vector2([self.data[0], self.data[1]])
		return returnValue

	def __mul__(self, other):
		if type(other) == type(self):
			returnValue = vector2([self.data[0] * other.data[0], self.data[1] * other.data[1]])
		elif type(other) == type(0.0) or type(other) == type(0):
			returnValue = vector2([self.data[0] * other, self.data[1] * other])
		else:
			returnValue = None
		return returnValue

	def __imul__(self, other):
		if type(other) == type(self):
			self.data[0] *= other.data[0]
			self.data[1] *= other.data[1]
			returnValue = vector2([self.data[0], self.data[1]])
		elif type(other) == type(0.0) or type(other) == type(0):
			self.data[0] *= other
			self.data[1] *= other
			returnValue = vector2([self.data[0], self.data[1]])
		else:
			returnValue = vector2([self.data[0], self.data[1]])
		return returnValue

	def __div__(self, other):
		if type(other) == type(self):
			returnValue = vector2([self.data[0] / float(other.data[0]), self.data[1] / float(other.data[1])])
		elif type(other) == type(0.0) or type(other) == type(0):
			returnValue = vector2([self.data[0] / float(other), self.data[1] / float(other)])
		else:
			returnValue = None
		return returnValue

	def __idiv__(self, other):
		if type(other) == type(self):
			self.data[0] /= other.data[0]
			self.data[1] /= other.data[1]
			returnValue = vector2([self.data[0], self.data[1]])
		elif type(other) == type(0.0) or type(other) == type(0):
			self.data[0] /= float(other)
			self.data[1] /= float(other)
			returnValue = vector2([self.data[0], self.data[1]])
		else:
			returnValue = vector2([self.data[0], self.data[1]])
		return returnValue

	def __neg__(self):
		return vector2([-self.data[0], -self.data[1]])

	def tuple(self):
		return self.data[0], self.data[1]

	def list(self):
		return [self.data[0], self.data[1]]

	def magnitude(self):
		return pow((self.data[0] * self.data[0]) + (self.data[1] * self.data[1]), 0.5)

	def normalize(self, overwrite = None):
		magnitude = self.magnitude()
		if magnitude != 0:
			returnX = self.data[0] / magnitude
			returnY = self.data[1] / magnitude
		else:
			returnX = 0.0
			returnY = 0.0
		if overwrite == True:
			self.data[0] = returnX
			self.data[1] = returnY
		if overwrite != True:
			return vector2([ \
			returnX, \
			returnY])
